<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="true" name="HandheldFriendly">
    <title></title>
    <meta content="" name="keywords"/>
    <meta content="" name="description"/>
    <link href="/web/css/normalize.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/style.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/animate.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="/web/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <div class="contain">
        <div class="sidebar" id="head">

        </div>
        <section>
            <div class="right_h" id="right_h">

            </div>
            <div class="qulicklink">
                <ul>
                    <li><a href="javascript:;"></a></li>
                    <li><a href="javascript:;"><span>企业首页</span><img src="/web/images/close.png"></a></li>
                    <li class="dq"><a href="javascript:;"><span>业务管理</span><img src="/web/images/close.png"></a></li>
                    <li><a href="javascript:;"></a></li>
                </ul>
            </div>
            <div class="breadcrumbs">
                <ul>
                    <li>系统设置</li>
                    <li>参数配置</li>
                </ul>
            </div>
            <div class="clearfix"></div>
            <div class="t_body parameter_body">
                <div class="parameterlist">
                    <div class="paratitle">参数类别</div>
                    <ul>
                        <li :class="{active : curIndex == v.id}"
                            :key="v.id"
                            @click="listClick(v.id)"
                            v-for="(v,index) in parameterList"
                        >{{v.title}}
                        </li>
                    </ul>
                </div>
                <div class="parameterright">
                    <div class="parametertop">
                        <div class="paratitle p_title">参数信息</div>
                        <div class="parameterbtn">
                            <div class="addbtn" v-if="sum(74)">
                                <a @click="addbtnClick()" href="javascript:;">新增</a>
                            </div>
                            <div class="deletebtn" v-if="sum(76)">
                                <a @click="deleteAllClick()" href="javascript:;">删除</a>
                            </div>


                            <div class="search">
                                <!--模糊查询开始-->
                                <label>
                                    <span>参数名:</span>
                                    <div class="searchbox">
                                        <input @input="search($event,'user','realname')" placeholder="请输入您要搜索的姓名"
                                               type="text">
                                    </div>
                                </label>
                                <!--模糊查询结束-->
                                <!--                                <div class="btns">-->
                                <!--                                    <div class="addbtn searchbtn">-->
                                <!--                                        <a @click="searchbtnClick()" href="javascript:;">搜索</a>-->
                                <!--                                    </div>-->
                                <!--                                    <div class="addbtn setbtn">-->
                                <!--                                        <a @click="resetbtnClick()" href="javascript:;">重置</a>-->
                                <!--                                    </div>-->
                                <!--                                </div>-->
                            </div>
                        </div>

                    </div>
                    <!--新增弹窗开始-->
                    <div class="addCharacter addParameter hidden">
                        <div class="addtitle">参数信息</div>
                        <div class="layerbody">
                            <label>
                                <span>参数名称:</span> <input class="paraname" name="resetTc" placeholder="请输入参数名称"
                                                          type="text" autocomplete="off" />
                            </label>
                            <label>
                                <span>状态:</span>
                                <input checked class="radio" name="status" type="radio" value="1"/> 有效
                                <input class="radio" id="wuxiao" name="status" type="radio" value="2"> 无效
                            </label>
                            <div class="btns_p">
                                <button @click="addsureBtn()" class="surebtn" type="submit">确认</button>
                                <button @click="addresetBtn()" class="resetbtn" type="submit">重置</button>
                            </div>
                        </div>
                    </div>
                    <!--新增弹窗结束-->
                    <div class="table-responsive">
                        <table class="table paratable" id="shuaxin">
                            <thead>
                            <tr>
                                <th><input @click="deleteCheckAll()" class="checkboxAll" id="deleteCheckAll"
                                           type="checkbox"> 全选
                                </th>
                                <th>序号</th>
                                <th style="text-align: left; padding-left: 25px">参数名</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr :key="index" @dblclick="editorClick(v.id)" v-for="(v,index) in paraList">
                                <td width="8%"><input :id="'listcheck' + (v.id)" class="selectCheck" type="checkbox">
                                </td>
                                <td width="6%">{{(parseInt(index) + 1)}}</td>
                                <td width="76%">{{v.title}}</td>
                                <td width="10%">
                                    <div class="editor" v-if="sum(75)">
                                        <a @click="editorClick(v.id)" href="javascript:;">
                                            <img src="images/editor.png">
                                        </a>
                                        <span>编辑</span>
                                    </div>
                                    <div class="deletes" v-if="sum(76)">
                                        <a @click="deletesClick(v.id)" href="javascript:;">
                                            <img src="images/deletes.png">
                                        </a>
                                        <span>删除</span>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="clearfix"></div>
                    <div class="parametertable">
                        <!---------------------------分页start----------------------------->
                        <div class="pageFen" v-if="totalNum>1">
                            <ul>
                                <li>
                                    <a @click="setPage(curNum-1)" class="pageLink" href="#">上一页</a>
                                </li>
                                <li v-for="n in totalNum">
                                    <a class="pageLink curNum" v-if="n == curNum" v-text="n"></a>
                                    <a @click="setPage(n)" class="pageLink" href="javascript:;" v-else v-text="n"></a>
                                </li>
                                <li><a @click="setPage(curNum+1)" class="pageLink" href="#">下一页</a></li>
                            </ul>
                        </div>
                        <!---------------------------分页end-------------------------------->
                    </div>
                </div>
            </div>
        </section>
    </div>
</div>
<script src="/web/js/vue.js"></script>
<script src="/web/js/jquery-1.10.0.min.js"></script>
<script src="/web/layui/layui.js"></script>
<script src="/web/js/transform.js"></script>
<script>
    layui.use('layer', function () {
        var $ = layui.$;
        // 加载hello组件（会自动绑定组件对应的dom上）
        $("#head").load("header.html");
        $("#right_h").load("right.html");
        getIndexData();

        function
    });
</script>
<script>
    AppData = new Vue({
        el: '#app',
        data: {
            tableData: {},
            categoryIndex: 0,
            show: false,
            parameterList: {},
            curIndex: 0,
            paraList: {},
            datasList: {},
            totalNum: 0, //总页数
            listRows: 8, //每页数量
            curNum: 1, //当前页码
            pid: 77,
            flag: 1,
            edid: 0
        },
        mounted() {
            $("#head").load("header.html");
            $("#right_h").load("right.html");
            this.getIndexData();
        },
        methods: {
            verification(data) {
                if (data.status == 2) {
                    layer.msg(data.message, {icon: 2, time: 1000}, function () {
                        window.location.href = "login.html";
                    });
                }
            },
            btnClick(id) {
                this.curIndex = id;
            },
            listClick(parapid) {
                this.curIndex = parapid;
                this.pid = parapid;
                localStorage.pid = parapid;
                AppData.curNum = 1;  //获取总的页面数
                console.log(this.pid);
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/parameter',
                    data: {'listRows': AppData.listRows, 'page': AppData.curNum, 'pid': AppData.pid},
                    success: function (data) {
                        AppData.verification(data);
                        let paraList = {...data.list.data};
                        console.log(paraList);
                        AppData.paraList = paraList;
                        AppData.totalNum = data.list.last_page;  //获取总的页面数
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            },
            sum(sumid) {//验证列表里的修改删除是否要显示(根据对应的id)
                for (let i in this.datasList) {
                    if (sumid == this.datasList[i].id) {
                        return true;
                    }
                }
                return false;
            },
            addbtnClick() {
                this.flag = 2;
                $('.paraname').val('');
                layeraddoredit = layer.open({
                    type: 1,
                    title: '新增参数',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    area: ['900px', '600px'],
                    content: $('.addCharacter'),
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.addCharacter').hide();
                    }
                })
            },
            addsureBtn() {
                let title = $('.paraname').val();
                let status = $('input[name="status"]:checked').val();
                if (!title) { //非空判断
                    layer.msg('请输入要添加的参数名', {icon: 2});
                    return false;
                }
                if (this.flag == 1) {
                    $.ajax({
                        type: "PUT",
                        dataType: "json",
                        url: '/parameter/' + this.edid,
                        data: {'title': title},
                        success: function (data) {
                            console.log(data);
                            AppData.verification(data);
                            if (data.status == 1) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    AppData.getIndexData();
                                    layer.close(layeraddoredit);
                                });
                            } else {
                                layer.msg(data.message, {icon: 2, time: 1000});
                            }
                        },
                        error: function (msg) {
                            console.log(msg);
                        }
                    });
                } else if (this.flag == 2) {
                    AppData.edid = 0;
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: '/parameter',
                        data: {'title': title, 'status': status, 'pid': this.pid},
                        success: function (data) {
                            console.log(data);
                            AppData.verification(data);
                            if (data.status == 1) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    AppData.getIndexData();
                                    layer.close(layeraddoredit);
                                });
                            } else {
                                layer.msg(data.message, {icon: 2, time: 1000});
                            }
                        },
                        error: function (msg) {
                            console.log(msg);
                        }
                    });
                }
            },
            setPage(num) {
                //页码小于等于1
                if (num < 1) {
                    num = 1;
                }
                //页码大于总页数
                if (num > this.totalNum) {
                    num = this.totalNum;
                }
                //页码赋给当前页
                this.curNum = num;
                getIndexData();
            },
            search(e, table, field) {
                var that = this;
                var keywords = e.target.value;
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/parameter/create',
                    data: {'keywords': keywords, 'pid': this.pid},
                    success: function (data) {
                        console.log(data);
                        AppData.verification(data);
                        AppData.paraList = data.list;
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            },
            editorClick(eid) {
                console.log(eid);
                this.flag = 1;
                AppData.edid = eid;
                layeraddoredit = layer.open({
                    type: 1,
                    title: '编辑菜单',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    area: ['900px', '600px'],
                    content: $('.addCharacter'),
                    success: function () {
                        $.ajax({
                            type: "GET",
                            dataType: "json",
                            url: '/parameter/' + eid,
                            data: {},
                            success: function (data) {
                                console.log(data);
                                AppData.verification(data);
                                $('.paraname').val(data.info.title);
                                if (data.info.status == 0) {
                                    $('#wuxiao').prop('checked', true);
                                }
                            },
                            error: function (msg) {
                                console.log(msg);
                            }
                        });
                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.addCharacter').hide();
                    }
                })
            },
            deletesClick(deleteid) {
                layui.use('layer', function () {
                    layer.confirm('确认要删除吗？', {
                        btn: ['确定', '取消']//按钮
                    }, function () {
                        let ids = [];
                        ids.push(deleteid);
                        $.ajax({
                            type: "DELETE",
                            dataType: "json",
                            url: '/parameter/0',
                            data: {'ids': ids},
                            success: function (data) {
                                AppData.verification(data);
                                if (data.status == 1) {
                                    layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                        AppData.getIndexData();
                                    });
                                } else {
                                    layer.msg(data.message, {icon: 2, time: 1000});
                                }
                            },
                            error: function (msg) {
                                console.log(msg);
                            }
                        });
                    });
                });
            },
            deleteCheckAll() {
                let checkBoxs = AppData.paraList;
                if ($('#deleteCheckAll').is(":checked")) {
                    for (let j in checkBoxs) {
                        $('#listcheck' + checkBoxs[j].id).prop('checked', true);
                    }
                } else {
                    for (let j in checkBoxs) {
                        $('#listcheck' + checkBoxs[j].id).prop('checked', false);
                    }
                }
            },
            deleteAllClick() {
                layui.use('layer', function () {
                    layer.confirm('确认要删除吗？', {
                        btn: ['确定', '取消']//按钮
                    }, function () {
                        let ids = [];
                        let checkBoxs = AppData.paraList;
                        for (let i in checkBoxs) {
                            if ($('#listcheck' + checkBoxs[i].id).is(":checked")) {
                                ids.push(checkBoxs[i].id);
                            }
                        }
                        if (ids.length == 0) {
                            layer.msg('请选择你要删除的选项');
                            return false;
                        }
                        console.log(ids);
                        $.ajax({
                            type: "DELETE",
                            dataType: "json",
                            url: '/parameter/0',
                            data: {'ids': ids},
                            success: function (data) {
                                console.log(data);
                                AppData.verification(data);
                                if (data.status == 1) {
                                    layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                        AppData.getIndexData();
                                    });
                                } else {
                                    layer.msg(data.message, {icon: 2, time: 1000});
                                }
                            },
                            error: function (msg) {
                                console.log(msg);
                            }
                        });
                    });
                });
            },
            addresetBtn() {
                $('input[name="resetTc"]').val('');
                $('select[name="resetTc"]').val('0');
                $('textarea[name="resetTc"]').val('');
            },
            //首页数据列表
            getIndexData() {
                if (localStorage.pid) {
                    this.pid = localStorage.pid;
                }
                this.btnClick(this.pid);
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/parameter',
                    data: {'listRows': this.listRows, 'page': this.curNum, 'pid': this.pid},
                    success: function (data) {
                        AppData.verification(data);
                        AppData.totalNum = data.list.last_page;  //获取总的页面数
                        let dataS = data.userInfo.jurisdiction;//后台初始数据
                        var dataArr = [];
                        for (let i in dataS) {
                            dataArr.push(dataS[i]); //属性
                        }
                        /*调用封装的改变数据结构方法*/
                        let tableData = setTreeData(dataArr);
                        let tableDataObj = {...tableData};//把转换后的数组通过扩展运算符改成对象便于遍历
                        AppData.tableData = tableDataObj;
                        //提取id从77到90的数据(参数列表)
                        let paraList = [];
                        for (let i in dataS) {
                            if (dataS[i].id > 76 && dataS[i].id < 93) {
                                paraList.push(dataS[i]);
                            }
                        }
                        let parameterList = {...paraList};
                        AppData.parameterList = parameterList;
                        //遍历出所有pid为62的数据
                        let dataListArr = [];
                        for (let i in dataS) {
                            if (dataS[i].pid == 62) {
                                dataListArr.push(dataS[i]);
                            }
                        }
                        let datasList = {...dataListArr};
                        AppData.datasList = datasList;
                        AppData.paraList = {...data.list.data};
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            }
        }
    })
</script>
</body>
</html>
